#include <iostream>
#include <string>
using namespace std;

int f[26][26];

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;

  cin >> n;
  for (int i = 0; i < 26; i++) {
    for (int j = 0; j < 26; j++) {
      f[i][j] = -1;
    }
  }

  for (int i = 0; i < n; i++) {
    string name;

    cin >> name;
    for (int j = 0; j < 26; j++) {
      if (f[j][name[0] - 'a'] != -1) {
        f[j][name.back() - 'a'] = max(f[j][name.back() - 'a'], f[j][name[0] - 'a'] + (int)name.size());
      }
    }
    f[name[0] - 'a'][name.back() - 'a'] = max((int)name.size(), f[name[0] - 'a'][name.back() - 'a']);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    ans = max(ans, f[i][i]);
  }
  cout << ans << "\n";
  return 0;
}